﻿using DevTool.Command;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DevTool.Contraner
{
    public partial class FileBase64Control : UserControl
    {
        public FileBase64Control()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 选择文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_Selelct_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.txt_fileroot.Text = this.openFileDialog1.FileName;
                if (!string.IsNullOrWhiteSpace(txt_fileroot.Text))
                {
                    var rdata = FileHelper.FileToBase64(this.txt_fileroot.Text.Trim());
                    this.rt_base64.Text = rdata;
                }

            }

        }
        /// <summary>
        /// 清空
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_clear_Click(object sender, EventArgs e)
        {
            this.rt_base64.Clear();
        }

        private void bt_Convter_Click(object sender, EventArgs e)
        {
            this.txt_fileroot.Text = this.openFileDialog1.FileName;
            if (!string.IsNullOrWhiteSpace(txt_fileroot.Text))
            {
                if (File.Exists(this.txt_fileroot.Text))
                {
                    var rdata = FileHelper.FileToBase64(this.txt_fileroot.Text.Trim());
                    this.rt_base64.Text = rdata;
                }
                else
                {
                    MessageBox.Show("该文件不存在！", "提示");
                }
            }
               
            else
            {
                MessageBox.Show("请选择文件！","提示");
            }
        }
    }
}
